package top.happylaishop.shop.controller.backend;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.happylaishop.shop.dto.ProductDetailDto;
import top.happylaishop.shop.dto.ProductDto;
import top.happylaishop.shop.service.CommonService;
import top.happylaishop.shop.service.FileService;
import top.happylaishop.shop.service.ProductService;
import top.happylaishop.shop.utils.resp.BaseResponse;
import top.happylaishop.shop.utils.resp.RestResponse;

@RestController
@RequestMapping("/manage/product")
public class ProductManageController {

    @Autowired
    private ProductService productService;
    @Autowired
    private FileService fileService;
    @Autowired
    private CommonService commonService;

    @PostMapping("/add")
    public BaseResponse add(@RequestBody ProductDto productDto){
        return productService.saveOrUpdateProduct(productDto, commonService.getCurrentUserInfo());
    }

    @PostMapping("/updateSaleStatusById")
    public BaseResponse updateSaleStatusById(@RequestBody ProductDto productDto) {
        return productService.updateSaleStatusById(productDto, commonService.getCurrentUserInfo());
    }

    @GetMapping("/detail/{id}")
    public RestResponse<ProductDetailDto> getDetailById(@PathVariable Integer id){
        return productService.getDetailById(id);
    }
}
